package tmproject.hlhj.fhp.cartrans.modules

import android.content.Context
import com.example.mymvp.BaseModule
import com.lzy.okgo.model.Response
import tmproject.hlhj.fhp.cartrans.http.Apis
import tmproject.hlhj.fhp.cartrans.http.BaseObserver
import tmproject.hlhj.fhp.cartrans.http.LoadingAction
import tmproject.hlhj.fhp.cartrans.javaBean.BaseBean
import tmproject.hlhj.fhp.cartrans.javaBean.ClassDetailBean
import tmproject.hlhj.fhp.cartrans.javaBean.SaveClassBean

/**
 * Created by Never Fear   on 2018\8\28 0028.
Never More....
 */
class ClassDetailModule :BaseModule {
    var listener:OnClassDetailListener?=null


    fun getClassDetail(id:Int,token:String?,c:Context){
        Apis.getClassDetail(id, token)
                ?.let {
                    it.doOnSubscribe(LoadingAction(c))
                            .subscribe(object :BaseObserver<Response<ClassDetailBean>>(c){
                                override fun failed(e: Throwable?) {
                                }

                                override fun httpSuccess(t: Response<ClassDetailBean>) {
                                    listener?.gotClassDetail(t.body())
                                }

                                override fun httpErroCode(baseBean: BaseBean) {
                                }
                            })
                }
    }

    fun saveClass(id: Int,token: String?,learned_time:String,c:Context){
        Apis.saveClass(token, id, learned_time)
                ?.let {
                    it.doOnSubscribe(LoadingAction(c))
                            .subscribe(object :BaseObserver<Response<SaveClassBean>>(c){
                                override fun failed(e: Throwable?) {
                                }

                                override fun httpSuccess(t: Response<SaveClassBean>) {
                                    listener?.saveClassResp(t.body())
                                }

                                override fun httpErroCode(baseBean: BaseBean) {
                                }
                            })
                }
    }
    interface OnClassDetailListener{
        fun gotClassDetail(classDetailBean: ClassDetailBean)

        fun saveClassResp(saveClassBean: SaveClassBean)
    }
}